package com.xxcxcxcx.xc_moremob.mixin;

import com.xxcxcxcx.xc_moremob.Main;
import com.xxcxcxcx.xc_moremob.common.event.FireworkRocketItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(FireworkRocketEntity.class)
public abstract class FireworkRocketEntityMixin extends Entity implements FireworkRocketItem {
    @Shadow @Final private static EntityDataAccessor<ItemStack> DATA_ID_FIREWORKS_ITEM;
    @Override
    public EntityDataAccessor<ItemStack> getDataIdFireworksItem(){
        return DATA_ID_FIREWORKS_ITEM;
    }


    public FireworkRocketEntityMixin(EntityType<?> p_19870_, Level p_19871_) {
        super(p_19870_, p_19871_);
    }
    @ModifyConstant(method = "dealExplosionDamage", constant = @Constant(floatValue = 5.0F))
    private float doubleRepairDurabilityBonus(float constant) {
        ItemStack itemstack = this.entityData.get(DATA_ID_FIREWORKS_ITEM);
        CompoundTag compoundtag = itemstack.isEmpty() ? null : itemstack.getTagElement(Main.MOD_ID);
        int damage = compoundtag != null ? compoundtag.getInt("Damage") : 0;
        return constant+damage;
    }
}
